﻿
'the key of a property in the storage is
'   id.name.type
'   such as, for the name of a node with id = 123 and handled by string_property will have a storage key as
'   123.name.string_proprty

Imports std

Public Class [property]
    Private Shared ReadOnly default_type As String = GetType([property]).Name()

    Public ReadOnly id As Int64 = 0
    Public ReadOnly name As String = Nothing
    Public ReadOnly type As String = Nothing
    Public ReadOnly key As String = Nothing

    Public Sub New(ByVal id As Int64, ByVal name As String, ByVal type As String)
        Me.id = id
        Me.name = name
        Me.type = type
        Me.key = create_node_property_key(id, name, type)
    End Sub

    Private Shared Function ctor(ByVal id As Int64,
                                 ByVal name As String) As [property]
        Return New [property](id, name, default_type)
    End Function

    Private Function io(ByVal ecc As _do(Of eventComb),
                        ByVal timeout_ms As Int64,
                        ByVal retry_wait_ms As Int64,
                        ByVal oper As String) As eventComb
        assert(Not ecc Is Nothing)
        Dim ec As eventComb = Nothing
        Return New eventComb(Function() As Boolean
                                 ec = ecc()
                                 assert(Not ec Is Nothing)
                                 Return waitfor(ec, timeout_ms) AndAlso goto_next()
                             End Function,
                             Function() As Boolean
                                 If ec.end_result() Then
                                     Return goto_end()
                                 Else
                                     raiseError(errorHandle.errorType.warning,
                                                "failed to ", oper, " ",
                                                key, ", retry in ", write_retry_wait_ms, " ms")
                                     Return waitfor(retry_wait_ms) AndAlso goto_prev()
                                 End If
                             End Function)
    End Function
End Class
